package xml;

import xml.elements.DataItem;
import xml.elements.DataItemSet;
import xml.elements.InitialState;
import xml.elements.Note;
import xml.elements.Output;
import xml.elements.PostCondition;
import xml.elements.PreCondition;
import xml.elements.RegularState;
import xml.elements.RegularTransitionFromOne;
import xml.elements.RegularTransitionFromSet;
import xml.elements.State;
import xml.elements.Structure;
import xml.elements.StructureSet;
import xml.elements.SubState;
import xml.elements.Uid;
import xml.elements.UidCall;
import xml.elements.UnidirectionalTransitionFromOne;
import xml.elements.UnidirectionalTransitionFromSet;
import xml.others.FacadeConstructorUID;
import xml.uidElements.UID;

public class FactoryUID extends ScannerUIDAbstract {

	private String idUID;
	private Uid uid;

	public FactoryUID(String idUID, String name) {
		this.idUID = idUID;
		FacadeConstructorUID.getInstance().newUID(idUID, name);
	}

	public UID insertElementsOfUid(Uid uidDiagram) {
		this.uid = uidDiagram;
		scanUID(uidDiagram);
		return FacadeConstructorUID.getInstance().getUID(idUID);
	}

	@Override
	protected void regularStateFound(RegularState o) {

		String idState = o.getId();

		FacadeConstructorUID.getInstance().insertState(idUID, idState);

		new FactoryState(idUID, o);
	}

	@Override
	protected void initialStateFound(InitialState o) {

		FacadeConstructorUID.getInstance().insertInitialState(idUID, o.getId());
		new FactoryState(idUID, o);

	}

	@Override
	protected void preConditionFound(PreCondition o) {
		FacadeConstructorUID.getInstance().insertPreCondition(idUID,
				o.getValue());
	}

	@Override
	protected void postConditionFound(PostCondition o) {
		FacadeConstructorUID.getInstance().insertPosCondition(idUID,
				o.getValue());
	}

	@Override
	protected void noteFound(Note o) {
		FacadeConstructorUID.getInstance().insertTextualNote(idUID,
				o.getValue());

	}

	@Override
	protected void uidCallFound(UidCall o) {
		
		//ARRUMAR AQUI...
		FacadeConstructorUID.getInstance().insertUIDCall(idUID, o.getName(), o.getName());

	}

	//
	// @Override
	// protected void regularTransitionFound(Object o) {
	// RegularTransition trans = (RegularTransition) o;
	//
	// String source = trans.getSource();
	//
	// String target = trans.getTarget();
	//
	// source = source.replaceAll("/", "");
	// target = target.replaceAll("/", "");
	//
	// String[] s = source.split("[@]+");
	// String[] t = target.split("[@]+");
	//
	// switch (s.length) {
	// case 2:
	// // Origem State
	// if (t.length == 2 && !t[1].contains("uidCalls")) {
	//
	// String[] idSourceState = s[1].split("[.]+");
	// String[] idTargetState = t[1].split("[.]+");
	//
	// FacadeConstructorUID.getInstance()
	// .insertTransitionFromStateToState(idUID,
	// idSourceState[1], idTargetState[1],
	// trans.getId());
	//
	// } else if (t.length == 2 && t[1].contains("uidCalls")) {
	// // transi��o para outro UID. N�o definido ainda.
	//
	// } else {
	// // transi��o para um SubState UID. N�o definido ainda.
	//
	// System.out.println(s[1]);
	// System.out.println(t[1]);
	//
	// String[] idSourceState = s[1].split("[.]+");
	// String[] idTargetState = t[1].split("[.]+");
	// String[] idTargetSubState = t[2].split("[.]+");
	//
	// System.out.println(idSourceState[1]);
	// System.out.println(idTargetState[1]);
	//
	// FacadeConstructorUID.getInstance()
	// .insertTransitionFromStateToSubState(idUID,
	// idSourceState[1], idTargetState[1],
	// idTargetSubState[1], trans.getId());
	//
	// }
	//
	// break;
	//
	// case 3:
	//
	// if (s[2].contains("substates")) {
	// // Origem SubState
	// if (t.length == 2 && !t[1].contains("uidCalls")) {
	// String[] idSourceState = s[1].split("[.]+");
	// String[] idTargetState = t[1].split("[.]+");
	// String[] idSourceSubState = s[2].split("[.]+");
	//
	// FacadeConstructorUID.getInstance()
	// .insertTransitionFromSubStateToState(idUID,
	// idSourceState[1], idSourceSubState[1],
	// idTargetState[1], trans.getId());
	// } else if (t.length == 2 && t[1].contains("uidCalls")) {
	// // transi��o para outro UID. N�o definido ainda.
	// } else {
	// // transi��o para um SubState UID. N�o definido ainda.
	// }
	// } else if (s[2].contains("dataItems")) {
	// // Origem DataItem
	// if (t.length == 2 && !t[1].contains("uidCalls")) {
	//
	// String[] idSourceState = s[1].split("[.]+");
	// String[] idTargetState = t[1].split("[.]+");
	// String[] idSourceDI = s[2].split("[.]+");
	// String idSourceDataItem = idSourceDI[1];
	//
	// for (Object a : diagram
	// .getStatesOrInitialStateOrTransitions()) {
	//
	// if (a.getClass().equals(State.class)) {
	//
	// if (((State) a).getId().equals(idSourceState[1])) {
	//
	// int i = 0;
	// for (Object b : ((State) a)
	// .getDataItemsOrStructuresOrUserInputs()) {
	// if (b.getClass().equals(DataItem.class)) {
	// if (Integer.valueOf(idSourceDI[1])
	// .equals(i)) {
	// idSourceDataItem = ((DataItem) b)
	// .getName();
	// break;
	// }
	// i++;
	// }
	// }
	// }
	// }
	// }
	//
	// FacadeConstructorUID.getInstance()
	// .insertTransitionFromDataItemToState(idUID,
	// idSourceState[1], idSourceDataItem,
	// idTargetState[1], trans.getId());
	//
	// } else if (t.length == 2 && t[1].contains("uidCalls")) {
	// // transi��o para outro UID. N�o definido ainda.
	// }
	// } else if (s[2].contains("structures")) {
	// // Origem Structure
	// if (t.length == 2 && !t[1].contains("uidCalls")) {
	// String[] idSourceState = s[1].split("[.]+");
	// String[] idTargetState = t[1].split("[.]+");
	// String[] idSourceS = s[2].split("[.]+");
	//
	// String idSourceStructure = idSourceS[1];
	//
	// for (Object a : diagram
	// .getStatesOrInitialStateOrTransitions()) {
	//
	// if (a.getClass().equals(State.class)) {
	//
	// if (((State) a).getId().equals(idSourceState[1])) {
	// int i = 0;
	// for (Object b : ((State) a)
	// .getDataItemsOrStructuresOrUserInputs()) {
	// if (b.getClass().equals(Structure.class)) {
	// if (Integer.valueOf(idSourceS[1])
	// .equals(i)) {
	// idSourceStructure = ((Structure) b)
	// .getName();
	// break;
	// }
	// i++;
	// }
	// }
	// break;
	// }
	// }
	// }
	//
	// FacadeConstructorUID.getInstance()
	// .insertTransitionFromStructureToState(idUID,
	// idSourceState[1], idSourceStructure,
	// idTargetState[1], trans.getId());
	//
	// } else if (t.length == 2 && t[1].contains("uidCalls")) {
	// // transi��o para outro UID. N�o definido ainda.
	// } else {
	// // transi��o para um SubState. N�o definido ainda.
	//
	// }
	//
	// }
	// break;
	//
	// case 4:
	//
	// if (s[3].contains("dataItems")) {
	// // Origem DataItem In SubState
	// if (t.length == 2 && !t[1].contains("uidCalls")) {
	//
	// String[] idTargetState = t[1].split("[.]+");
	// String[] idSourceState = s[1].split("[.]+");
	// String[] idSourceSubState = s[2].split("[.]+");
	// String[] idSourceDI = s[3].split("[.]+");
	// String idSourceDataItem = idSourceDI[1];
	//
	// for (Object a : diagram
	// .getStatesOrInitialStateOrTransitions()) {
	// if (a.getClass().equals(State.class)) {
	// if (((State) a).getId().equals(idSourceState[1])) {
	// for (Object b : ((State) a)
	// .getDataItemsOrStructuresOrUserInputs()) {
	// if (b.getClass().equals(Substate.class)) {
	// if (((Substate) b).getId().equals(
	// idSourceSubState[1])) {
	// int j = 0;
	// for (Object c : ((Substate) b)
	// .getDataItemsOrStructuresOrUserInputs()) {
	// if (c.getClass().equals(
	// DataItem.class)) {
	// if (Integer.valueOf(
	// idSourceDI[1])
	// .equals(j)) {
	// idSourceDataItem = ((DataItem) c)
	// .getName();
	// break;
	// }
	// j++;
	// }
	// }
	// break;
	// }
	// }
	// }
	// }
	// }
	// }
	//
	// FacadeConstructorUID.getInstance()
	// .insertTransitionFromDataItemInSubStateToState(
	// idUID, idSourceState[1],
	// idSourceSubState[1], idSourceDataItem,
	// idTargetState[1], trans.getId());
	//
	// } else if (t.length == 2 && t[1].contains("uidCalls")) {
	// // transi��o para outro UID. N�o definido ainda.
	// } else {
	// // transi��o para um SubState UID. N�o definido ainda.
	// }
	// } else if (s[3].contains("structures")) {
	// // Origem Structure In SubState
	// if (t.length == 2 && !t[1].contains("uidCalls")) {
	// String[] idTargetState = t[1].split("[.]+");
	// String[] idSourceState = s[1].split("[.]+");
	// String[] idSourceSubState = s[2].split("[.]+");
	// String[] idSourceS = s[3].split("[.]+");
	//
	// String idSourceStructure = idSourceS[1];
	//
	// for (Object a : diagram
	// .getStatesOrInitialStateOrTransitions()) {
	// if (a.getClass().equals(State.class)) {
	// if (((State) a).getId().equals(idSourceState[1])) {
	// for (Object b : ((State) a)
	// .getDataItemsOrStructuresOrUserInputs()) {
	// if (b.getClass().equals(Substate.class)) {
	// if (((Substate) b).getId().equals(
	// idSourceSubState[1])) {
	// int i = 0;
	// for (Object c : ((Substate) b)
	// .getDataItemsOrStructuresOrUserInputs()) {
	// if (c.getClass().equals(
	// Structure.class)) {
	// if (Integer.valueOf(
	// idSourceS[1])
	// .equals(i)) {
	// idSourceStructure = ((Structure) c)
	// .getName();
	// break;
	// }
	// i++;
	// }
	// }
	// break;
	// }
	// }
	// }
	// }
	// }
	// }
	//
	// FacadeConstructorUID.getInstance()
	// .insertTransitionFromStructureInSubStateToState(
	// idUID, idSourceState[1],
	// idSourceSubState[1], idSourceStructure,
	// idTargetState[1], trans.getId());
	//
	// } else if (t.length == 2 && t[1].contains("uidCalls")) {
	// // transi��o para outro UID. N�o definido ainda.
	// }
	//
	// }
	// break;
	// }
	//
	// }

	@Override
	protected void regularTransitionFromOneFound(RegularTransitionFromOne o) {

		String[] source = o.getSource().replaceAll("/", "").split("@");
		String[] target = o.getTarget().replaceAll("/", "").split("@");

		switch (source.length) {

		case 2:

			if (target[1].contains("state")) {

				FacadeConstructorUID.getInstance().insertTransitionFromStateToState(idUID,
								source[1].replace(".", ""),
								target[1].replace(".", ""), o.getId(),
								o.getCondition(), o.getOption());

			} else if (target[1].contains("uidcalls")) {

				UidCall u = null;
				int i = 0;
				for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

					if (a instanceof UidCall) {

						if (Integer.valueOf((target[1].split("[.]+"))[1]).equals(i)) {
							u = (UidCall) a;
							break;
						}
						i++;
					}
					
				}

				FacadeConstructorUID.getInstance().insertTransitionFromStateToUIDCall(idUID,
								source[1].replace(".", ""), u.getName(),
								o.getId(), o.getCondition(), o.getOption());

			}

			break;

		case 3:

			if (source[2].contains("substates")) {

				if (target[1].contains("state")) {

					FacadeConstructorUID.getInstance().insertTransitionFromSubStateToState(idUID,
									source[1].replace(".", ""),
									source[2].replace(".", ""),
									target[1].replace(".", ""), o.getId(),
									o.getCondition(), o.getOption());

				} else if (target[1].contains("uidcalls")) {

					UidCall u = null;
					int i = 0;
					for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

						if (a instanceof UidCall) {

							if (Integer.valueOf((target[1].split("[.]+"))[1]).equals(i)) {
								u = (UidCall) a;
								break;
							}

							i++;
						}
					}

					FacadeConstructorUID.getInstance()
							.insertTransitionFromSubStateToUIDCall(idUID,
									source[1].replace(".", ""),
									source[2].replace(".", ""), u.getName(),
									o.getId(), o.getCondition(), o.getOption());

				}

			} else {

				Output out = null;

				for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

					if (a instanceof State) {

						if (((State) a).getId().equals(source[1].replace(".", ""))) {
							int i = 0;
							for (Object b : ((State) a).getInputsOrOutputsOrTexts()) {
								if (b instanceof Output) {
									if (Integer.valueOf((source[2].split("[.]+"))[1]).equals(i)) {
										out = (Output) b;
										break;
									}
									i++;
								}
							}
						}
					}
				}

				if (out instanceof Structure) {

					if (target[1].contains("state")) {
						FacadeConstructorUID.getInstance()
								.insertTransitionFromStructureToState(idUID,
										source[1].replace(".", ""),
										((Structure) out).getName(),
										target[1].replace(".", ""), o.getId(),
										o.getCondition(), o.getOption());

					} else if (target[1].contains("uidcalls")) {

						UidCall u = null;
						int i = 0;
						for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

							if (a instanceof UidCall) {

								if (Integer.valueOf((target[1].split("[.]+"))[1]).equals(i)) {
									u = (UidCall) a;
									break;
								}

							}
							i++;
						}
						FacadeConstructorUID.getInstance().insertTransitionFromStructureToUIDCall(idUID,
										source[1].replace(".", ""),((Structure) out).getName(),
										u.getName(), o.getId(),o.getCondition(), o.getOption());

					}

				} else {

					if (target[1].contains("state")) {
						FacadeConstructorUID.getInstance().insertTransitionFromDataItemToState(idUID,
										source[1].replace(".", ""),((DataItem) out).getName(),
										target[1].replace(".", ""), o.getId(),o.getCondition(), o.getOption());
					} else if (target[1].contains("uidcalls")) {

						UidCall u = null;
						int i = 0;
						for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

							if (a instanceof UidCall) {

								if (Integer.valueOf((target[1].split("[.]+"))[1]).equals(i)) {
									u = (UidCall) a;
									break;
								}

							}
							i++;
						}

						FacadeConstructorUID.getInstance()
								.insertTransitionFromDataItemToUIDCall(idUID,
										source[1].replace(".", ""),
										((DataItem) out).getName(),
										u.getName(), o.getId(),
										o.getCondition(), o.getOption());

					}

				}

			}

			break;

		case 4:

			Output out = null;

			for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

				if (a instanceof State) {

					if (((State) a).getId().equals(source[1].replace(".", ""))) {

						int j = 0;
						for (Object s : ((State) a).getInputsOrOutputsOrTexts()) {

							if (s instanceof SubState) {
								if (Integer.valueOf((source[2].split("[.]+"))[1]).equals(j)) {
									int i = 0;
									for (Object b : ((SubState) s).getInputsOrOutputsOrTexts()) {
										if (b instanceof Output) {
											if (Integer.valueOf((source[3].split("[.]+"))[1]).equals(i)) {
												out = (Output) b;
												break;
											}
											i++;
										}
									}
								}
								j++;
							}
						}
					}
				}
			}

			if (out instanceof Structure) {

				if (target[1].contains("state")) {
					FacadeConstructorUID.getInstance().insertTransitionFromStructureInSubStateToState(
									idUID, source[1].replace(".", ""),source[2].replace(".", ""),
									((Structure) out).getName(),target[1].replace(".", ""), o.getId(),
									o.getCondition(), o.getOption());

				} else if (target[1].contains("uidcalls")) {

					UidCall u = null;
					int i = 0;
					for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

						if (a instanceof UidCall) {

							if (Integer.valueOf((target[1].split("[.]+"))[1]).equals(i)) {
								u = (UidCall) a;
								break;
							}

						}
						i++;
					}

					FacadeConstructorUID.getInstance()
							.insertTransitionFromStructureInSubStateToUIDCall(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""),
									((Structure) out).getName(), u.getName(),
									o.getId(), o.getCondition(), o.getOption());

				}

			} else {

				if (target[1].contains("state")) {
					FacadeConstructorUID.getInstance().insertTransitionFromDataItemInSubStateToState(
							idUID, source[1].replace(".", ""),source[2].replace(".", ""),
							((DataItem) out).getName(),target[1].replace(".", ""), o.getId(),
							o.getCondition(), o.getOption());
				} else if (target[1].contains("uidcalls")) {

					UidCall u = null;
					int i = 0;
					for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

						if (a instanceof UidCall) {

							if (Integer.valueOf((target[1].split("[.]+"))[1]).equals(i)) {
								u = (UidCall) a;
								break;
							}

						}
						i++;
					}

					FacadeConstructorUID.getInstance().insertTransitionFromDataItemInSubStateToUIDCall(idUID,
									source[1].replace(".", ""),source[2].replace(".", ""),
									((DataItem) out).getName(), u.getName(),
									o.getId(), o.getCondition(), o.getOption());

				}

			}

			break;

		}

	}

	@Override
	protected void regularTransitionFromSetFound(RegularTransitionFromSet o) {

		String[] source = o.getSource().replaceAll("/", "").split("@");
		String[] target = o.getTarget().replaceAll("/", "").split("@");

		switch (source.length) {

		case 3:

			Output out = null;

			for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

				if (a instanceof State) {

					if (((State) a).getId().equals(source[1].replace(".", ""))) {
						int i = 0;
						for (Object b : ((State) a).getInputsOrOutputsOrTexts()) {
							if (b instanceof Output) {
								if (Integer.valueOf((source[2].split("[.]+"))[1]).equals(i)) {
									out = (Output) b;
									break;
								}
								i++;
							}
						}
					}
				}
			}

			if (out instanceof StructureSet) {

				if (target[1].contains("state")) {
					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID.getInstance().insertTransitionFromSetStructureToState(idUID,
									source[1].replace(".", ""),((StructureSet) out).getName(),
									target[1].replace(".", ""), o.getId(),o.getCondition(), o.getOption(), number);

				} else if (target[1].contains("uidcalls")) {
					UidCall u = null;
					int i = 0;
					for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

						if (a instanceof UidCall) {

							if (Integer.valueOf((target[1].split("[.]+"))[1]).equals(i)) {
								u = (UidCall) a;
								break;
							}

							i++;

						}
					}

					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID.getInstance().insertTransitionFromSetStructureToUIDCall(idUID,
									source[1].replace(".", ""),((StructureSet) out).getName(),
									u.getName(), o.getId(), o.getCondition(),o.getOption(), number);

				}

			} else {

				if (target[1].contains("state")) {
					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID.getInstance()
							.insertTransitionFromSetDataItemToState(idUID,
									source[1].replace(".", ""),
									((DataItemSet) out).getName(),
									target[1].replace(".", ""), o.getId(),
									o.getCondition(), o.getOption(), number);
				} else if (target[1].contains("uidcalls")) {

					UidCall u = null;
					int i = 0;
					for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

						if (a instanceof UidCall) {

							if (Integer.valueOf((target[1].split("[.]+"))[1])
									.equals(i)) {
								u = (UidCall) a;
								break;
							}

						}
						i++;
					}

					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID.getInstance()
							.insertTransitionFromSetDataItemToUIDCall(idUID,
									source[1].replace(".", ""),
									((DataItemSet) out).getName(), u.getName(),
									o.getId(), o.getCondition(), o.getOption(),
									number);

				}

			}

			break;

		case 4:

			Output out1 = null;

			for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

				if (a instanceof State) {

					if (((State) a).getId().equals(source[1].replace(".", ""))) {

						int j = 0;
						for (Object s : ((State) a).getInputsOrOutputsOrTexts()) {

							if (s instanceof SubState) {
								if (Integer.valueOf(
										(source[2].split("[.]+"))[1]).equals(j)) {
									int i = 0;
									for (Object b : ((SubState) s)
											.getInputsOrOutputsOrTexts()) {
										if (b instanceof Output) {
											if (Integer.valueOf((source[3].split("[.]+"))[1]).equals(i)) {
												out1 = (Output) b;
												break;
											}
											i++;
										}
									}
								}
								j++;
							}
						}
					}
				}
			}

			if (out1 instanceof StructureSet) {

				if (target[1].contains("state")) {
					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID.getInstance()
							.insertTransitionFromSetStructureInSubStateToState(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""),
									((StructureSet) out1).getName(),
									target[1].replace(".", ""), o.getId(),
									o.getCondition(), o.getOption(), number);

				} else if (target[1].contains("uidcalls")) {

					UidCall u = null;
					int i = 0;
					for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

						if (a instanceof UidCall) {

							if (Integer.valueOf((target[1].split("[.]+"))[1])
									.equals(i)) {
								u = (UidCall) a;
								break;
							}

						}
						i++;
					}
					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID.getInstance()
							.insertTransitionFromSetStructureInSubStateToUIDCall(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""),
									((StructureSet) out1).getName(),
									u.getName(), o.getId(), o.getCondition(),
									o.getOption(), number);

				}

			} else {

				if (target[1].contains("state")) {
					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID.getInstance()
							.insertTransitionFromSetDataItemInSubStateToState(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""),
									((DataItemSet) out1).getName(),
									target[1].replace(".", ""), o.getId(),
									o.getCondition(), o.getOption(), number);
				} else if (target[1].contains("uidcalls")) {

					UidCall u = null;
					int i = 0;
					for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

						if (a instanceof UidCall) {

							if (Integer.valueOf((target[1].split("[.]+"))[1])
									.equals(i)) {
								u = (UidCall) a;
								break;
							}

						}
						i++;
					}

					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID.getInstance()
							.insertTransitionFromSetDataItemInSubStateToUIDCall(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""),
									((DataItemSet) out1).getName(),
									u.getName(), o.getId(), o.getCondition(),
									o.getOption(), number);

				}

			}

			break;

		}

	}

	@Override
	protected void unidirectionalTransitionFromOneFound(
			UnidirectionalTransitionFromOne o) {

		String[] source = o.getSource().replaceAll("/", "").split("@");
		String[] target = o.getTarget().replaceAll("/", "").split("@");

		switch (source.length) {

		case 2:

			if (target[1].contains("state")) {

				FacadeConstructorUID.getInstance()
						.insertTransitionNoReturnableFromStateToState(idUID,
								source[1].replace(".", ""),
								target[1].replace(".", ""), o.getId(),
								o.getCondition(), o.getOption());

			} else if (target[1].contains("uidcalls")) {

				UidCall u = null;
				int i = 0;
				for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

					if (a instanceof UidCall) {

						if (Integer.valueOf((target[1].split("[.]+"))[1])
								.equals(i)) {
							u = (UidCall) a;
							break;
						}

					}
					i++;
				}
				FacadeConstructorUID.getInstance()
						.insertTransitionNoReturnableFromStateToUIDCall(idUID,
								source[1].replace(".", ""), u.getName(),
								o.getId(), o.getCondition(), o.getOption());
			}

			break;

		case 3:

			if (source[2].contains("substates")) {

				if (target[1].contains("state")) {

					FacadeConstructorUID.getInstance()
							.insertTransitionNoReturnableFromSubStateToState(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""),
									target[1].replace(".", ""), o.getId(),
									o.getCondition(), o.getOption());

				} else if (target[1].contains("uidcalls")) {

					UidCall u = null;
					int i = 0;
					for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

						if (a instanceof UidCall) {

							if (Integer.valueOf((target[1].split("[.]+"))[1])
									.equals(i)) {
								u = (UidCall) a;
								break;
							}

						}
						i++;
					}
					FacadeConstructorUID.getInstance()
							.insertTransitionNoReturnableFromSubStateToUIDCall(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""), u.getName(),
									o.getId(), o.getCondition(), o.getOption());

				}

			} else {

				Output out = null;

				for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

					if (a instanceof State) {

						if (((State) a).getId().equals(
								source[1].replace(".", ""))) {
							int i = 0;
							for (Object b : ((State) a)
									.getInputsOrOutputsOrTexts()) {
								if (b instanceof Output) {
									if (Integer.valueOf(
											(source[2].split("[.]+"))[1])
											.equals(i)) {
										out = (Output) b;
										break;
									}
									i++;
								}
							}
						}
					}
				}

				if (out instanceof Structure) {

					if (target[1].contains("state")) {
						FacadeConstructorUID
								.getInstance()
								.insertTransitionNoReturnableFromStructureToState(
										idUID, source[1].replace(".", ""),
										((Structure) out).getName(),
										target[1].replace(".", ""), o.getId(),
										o.getCondition(), o.getOption());

					} else if (target[1].contains("uidcalls")) {

						UidCall u = null;
						int i = 0;
						for (Object a : uid
								.getStatesOrInitialStateOrTransitions()) {

							if (a instanceof UidCall) {

								if (Integer.valueOf(
										(target[1].split("[.]+"))[1]).equals(i)) {
									u = (UidCall) a;
									break;
								}

							}
							i++;
						}
						FacadeConstructorUID
								.getInstance()
								.insertTransitionNoReturnableFromStructureToUIDCall(
										idUID, source[1].replace(".", ""),
										((Structure) out).getName(),
										u.getName(), o.getId(),
										o.getCondition(), o.getOption());

					}

				} else {

					if (target[1].contains("state")) {
						FacadeConstructorUID
								.getInstance()
								.insertTransitionNoReturnableFromDataItemToState(
										idUID, source[1].replace(".", ""),
										((DataItem) out).getName(),
										target[1].replace(".", ""), o.getId(),
										o.getCondition(), o.getOption());
					} else if (target[1].contains("uidcalls")) {

						UidCall u = null;
						int i = 0;
						for (Object a : uid
								.getStatesOrInitialStateOrTransitions()) {

							if (a instanceof UidCall) {

								if (Integer.valueOf(
										(target[1].split("[.]+"))[1]).equals(i)) {
									u = (UidCall) a;
									break;
								}

							}
							i++;
						}
						FacadeConstructorUID.getInstance()
								.insertTransitionNoReturnableFromDataItemToUIDCall(
										idUID, source[1].replace(".", ""),
										((DataItem) out).getName(),
										u.getName(), o.getId(),
										o.getCondition(), o.getOption());
					}

				}

			}

			break;

		case 4:

			Output out = null;

			for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

				if (a instanceof State) {

					if (((State) a).getId().equals(source[1].replace(".", ""))) {

						int j = 0;
						for (Object s : ((State) a).getInputsOrOutputsOrTexts()) {

							if (s instanceof SubState) {
								if (Integer.valueOf(
										(source[2].split("[.]+"))[1]).equals(j)) {
									int i = 0;
									for (Object b : ((SubState) s)
											.getInputsOrOutputsOrTexts()) {
										if (b instanceof Output) {
											if (Integer
													.valueOf(
															(source[3]
																	.split("[.]+"))[1])
													.equals(i)) {
												out = (Output) b;
												break;
											}
											i++;
										}
									}
								}
								j++;
							}
						}
					}
				}
			}

			if (out instanceof Structure) {

				if (target[1].contains("state")) {
					FacadeConstructorUID
							.getInstance()
							.insertTransitionNoReturnableFromStructureInSubStateToState(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""),
									((Structure) out).getName(),
									target[1].replace(".", ""), o.getId(),
									o.getCondition(), o.getOption());

				} else if (target[1].contains("uidcalls")) {

					UidCall u = null;
					int i = 0;
					for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

						if (a instanceof UidCall) {

							if (Integer.valueOf((target[1].split("[.]+"))[1])
									.equals(i)) {
								u = (UidCall) a;
								break;
							}

						}
						i++;
					}
					FacadeConstructorUID
							.getInstance()
							.insertTransitionNoReturnableFromStructureInSubStateToUIDCall(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""),
									((Structure) out).getName(), u.getName(),
									o.getId(), o.getCondition(), o.getOption());
				}

			} else {

				if (target[1].contains("state")) {
					FacadeConstructorUID
							.getInstance()
							.insertTransitionNoReturnableFromDataItemInSubStateToState(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""),
									((DataItem) out).getName(),
									target[1].replace(".", ""), o.getId(),
									o.getCondition(), o.getOption());
				} else if (target[1].contains("uidcalls")) {

					UidCall u = null;
					int i = 0;
					for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

						if (a instanceof UidCall) {

							if (Integer.valueOf((target[1].split("[.]+"))[1])
									.equals(i)) {
								u = (UidCall) a;
								break;
							}

						}
						i++;
					}

					FacadeConstructorUID
							.getInstance()
							.insertTransitionNoReturnableFromDataItemInSubStateToUIDCall(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""),
									((DataItem) out).getName(), u.getName(),
									o.getId(), o.getCondition(), o.getOption());

				}

			}

			break;

		}

	}

	@Override
	protected void unidirectionalTransitionFromSetFound(
			UnidirectionalTransitionFromSet o) {

		String[] source = o.getSource().replaceAll("/", "").split("@");
		String[] target = o.getTarget().replaceAll("/", "").split("@");

		switch (source.length) {

		case 3:

			Output out = null;

			for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

				if (a instanceof State) {

					if (((State) a).getId().equals(source[1].replace(".", ""))) {
						int i = 0;
						for (Object b : ((State) a).getInputsOrOutputsOrTexts()) {
							if (b instanceof Output) {
								if (Integer.valueOf(
										(source[2].split("[.]+"))[1]).equals(i)) {
									out = (Output) b;
									break;
								}
								i++;
							}
						}
					}
				}
			}

			if (out instanceof StructureSet) {

				if (target[1].contains("state")) {
					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID
							.getInstance()
							.insertTransitionNoReturnableFromSetStructureToState(
									idUID, source[1].replace(".", ""),
									((StructureSet) out).getName(),
									target[1].replace(".", ""), o.getId(),
									o.getCondition(), o.getOption(), number);

				} else if (target[1].contains("uidcalls")) {

					UidCall u = null;
					int i = 0;
					for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

						if (a instanceof UidCall) {

							if (Integer.valueOf((target[1].split("[.]+"))[1])
									.equals(i)) {
								u = (UidCall) a;
								break;
							}

						}
						i++;
					}
					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID.getInstance()
							.insertTransitionNoReturnableFromSetStructureToUIDCall(
									idUID, source[1].replace(".", ""),
									((StructureSet) out).getName(),
									u.getName(), o.getId(), o.getCondition(),
									o.getOption(), number);
				}

			} else {

				if (target[1].contains("state")) {
					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID
							.getInstance()
							.insertTransitionNoReturnableFromSetDataItemToState(
									idUID, source[1].replace(".", ""),
									((DataItemSet) out).getName(),
									target[1].replace(".", ""), o.getId(),
									o.getCondition(), o.getOption(), number);
				} else if (target[1].contains("uidcalls")) {

					UidCall u = null;
					int i = 0;
					for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

						if (a instanceof UidCall) {

							if (Integer.valueOf((target[1].split("[.]+"))[1])
									.equals(i)) {
								u = (UidCall) a;
								break;
							}

						}
						i++;
					}
					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID.getInstance()
							.insertTransitionNoReturnableFromSetDataItemToUIDCall(
									idUID, source[1].replace(".", ""),
									((DataItemSet) out).getName(), u.getName(),
									o.getId(), o.getCondition(), o.getOption(),
									number);

				}

			}

			break;

		case 4:

			Output out1 = null;

			for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

				if (a instanceof State) {

					if (((State) a).getId().equals(source[1].replace(".", ""))) {

						int j = 0;
						for (Object s : ((State) a).getInputsOrOutputsOrTexts()) {

							if (s instanceof SubState) {
								if (Integer.valueOf(
										(source[2].split("[.]+"))[1]).equals(j)) {
									int i = 0;
									for (Object b : ((SubState) s)
											.getInputsOrOutputsOrTexts()) {
										if (b instanceof Output) {
											if (Integer
													.valueOf(
															(source[3]
																	.split("[.]+"))[1])
													.equals(i)) {
												out1 = (Output) b;
												break;
											}
											i++;
										}
									}
								}
								j++;
							}
						}
					}
				}
			}

			if (out1 instanceof StructureSet) {

				if (target[1].contains("state")) {
					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID
							.getInstance()
							.insertTransitionNoReturnableFromSetStructureInSubStateToState(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""),
									((StructureSet) out1).getName(),
									target[1].replace(".", ""), o.getId(),
									o.getCondition(), o.getOption(), number);

				} else if (target[1].contains("uidcalls")) {

					UidCall u = null;
					int i = 0;
					for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

						if (a instanceof UidCall) {

							if (Integer.valueOf((target[1].split("[.]+"))[1])
									.equals(i)) {
								u = (UidCall) a;
								break;
							}

						}
						i++;
					}
					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID
							.getInstance()
							.insertTransitionNoReturnableFromSetStructureInSubStateToUIDCall(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""),
									((StructureSet) out1).getName(),
									u.getName(), o.getId(), o.getCondition(),
									o.getOption(), number);
				}

			} else {

				if (target[1].contains("state")) {
					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID
							.getInstance()
							.insertTransitionNoReturnableFromSetDataItemInSubStateToState(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""),
									((DataItemSet) out1).getName(),
									target[1].replace(".", ""), o.getId(),
									o.getCondition(), o.getOption(), number);
				} else if (target[1].contains("uidcalls")) {

					UidCall u = null;
					int i = 0;
					for (Object a : uid.getStatesOrInitialStateOrTransitions()) {

						if (a instanceof UidCall) {

							if (Integer.valueOf((target[1].split("[.]+"))[1])
									.equals(i)) {
								u = (UidCall) a;
								break;
							}
							i++;
						}

					}
					Integer number = o.getNumber();
					if (number == null)
						number = 0;
					FacadeConstructorUID
							.getInstance()
							.insertTransitionNoReturnableFromSetDataItemInSubStateToUIDCall(
									idUID, source[1].replace(".", ""),
									source[2].replace(".", ""),
									((DataItemSet) out1).getName(),
									u.getName(), o.getId(), o.getCondition(),
									o.getOption(), number);
				}

			}

			break;

		}

	}
}
